home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / asynlib2.zip / TERM.C < prev    next >
Text File  |  1980-03-19  |  2KB  |  73 lines

  1. /*
  2.     Simple-Term
  3.  
  4.     A short terminal emulation package to show the use of the
  5.     ASYNC communications library.
  6.  
  7.     In case you are wondering, the COM Port settings are hard coded in
  8.     the defines right before main(), change these as you wish.
  9.  
  10.     Also, this program does not emulate any known terminal.  Instead
  11.     it outputs all text via DOS, so if you run ANSI.SYS then you can
  12.     have a more useable program-- but since this is an example anyway, 
  13.     I sure you don't mind.  
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <conio.h>
  19. #include "async.h"
  20.  
  21. #define    COM_PORT    COM1
  22. #define BAUD_RATE    38400
  23. #define    COM_SETTINGS    (BITS_8 | STOP_1 | NO_PARITY)
  24.  
  25. int    main()
  26. {
  27. int    c;
  28.  
  29. printf( "Simple-Term.  Press F10 to Quit.\n\n");
  30.  
  31. if( AsyncInit( COM_PORT))
  32.     {
  33.     printf( "Error initalizing COM Port.\n");
  34.     return(1);
  35.     }
  36.  
  37. AsyncSet( BAUD_RATE, COM_SETTINGS);
  38. AsyncHand( DTR | RTS);
  39.  
  40. for(;;)
  41.     {
  42.     /*    If a character was recieved, print it to the console */
  43.     if( (c=AsyncIn())!=0)
  44.         putch( c);
  45.  
  46.     /*    If a key has been pressed    */
  47.     if( kbhit() )
  48.         {
  49.         c=getch();
  50.         if( c==0)    /* Check for 'extended characters */
  51.             {
  52.             c=getch();    /* Get the extended code */
  53.             if( c==0x44)    /* Exit if it is a F10 */
  54.                 break;
  55.             }
  56.         else
  57.             AsyncOut(c);
  58.         }
  59.  
  60.     /*    If the buffer has a lot in it, drop RTS and empty the buffer */
  61.     if( AsyncInStat()>4096)
  62.         {
  63.         AsyncHand( DTR);    /* Drop RTS */
  64.         while( AsyncInStat()>0)
  65.             putch( AsyncIn() );
  66.         AsyncHand( DTR | RTS);
  67.         }
  68.     }
  69.  
  70. AsyncStop();
  71. return(0);
  72. }
  73.